﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DAO.BLL;
using System.Text;
using NHibernate.Criterion;
using Common;

namespace Web.helper
{
    public static class HtmlMenu
    {
        public static string Menu(this HtmlHelper helper,string userName)
        {
            B_Navigation b_nav = new B_Navigation();
            //先查询出所有的一级菜单
            List<Order> order = new List<Order>() { Order.Asc("sort_id") };
            var list_nav = b_nav.LoadAll(order, 0);
            StringBuilder sb = new StringBuilder();

            foreach (var nav in list_nav)
            {
                sb.Append("<li>");
                sb.Append("<a href=\"" + nav.link_url + "\">");
                sb.Append(nav.icon_url);
                sb.Append("<span class=\"nav-label\">" + nav.title + "</span>");
                sb.Append("<span class=\"fa arrow\"></span>");
                sb.Append("</a>");
                sb.Append("<ul class=\"nav nav-second-level\">");
                //查询二级菜单
                var list_sub_nav = b_nav.LoadAll(order, nav.id);
                foreach (var sub_nav in list_sub_nav)
                {
                    sb.Append("<li>");
                    sb.Append("<a class=\"J_menuItem\" href=" + ConfigPath.GetTempletPaht(sub_nav.link_url) + " data-index=" + sub_nav.sort_id + ">" + sub_nav.icon_url + "</i>" + sub_nav.title + "</a>");
                    sb.Append("</li>");
                }
                sb.Append("</ul>");
                sb.Append("</li>");

            }
            return sb.ToString();
        }
    }
}